package com.ruoyi.system.webgroupservcie.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.webgroup.Clock;
import com.ruoyi.system.domain.webgroup.DailyList;
import com.ruoyi.system.domain.webgroup.GeneralList;
import com.ruoyi.system.domain.webgroup.WeeklyList;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.webgroupmapper.ClockMapper;
import com.ruoyi.system.webgroupservcie.ClockService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Time;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ClockServiceImpl implements ClockService {
    @Autowired
    private ClockMapper clockMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<Clock> selectClockAll(Clock clock) {
        List<Clock> clocks = clockMapper.selectClockAll(clock);
        for(Clock clock1 : clocks){
            SysUser sysUser = sysUserMapper.selectUserById((long) clock1.getUserId());
            clock1.setSysUser(sysUser);
        }
        return clocks;
    }

    @Override
    public Clock getClock(Integer clockId) {
        return clockMapper.getClock(clockId);
    }

    @Override
    public int deleteClock(Integer[] clockIds) {
        return clockMapper.deleteClock(clockIds);
    }

    @Override
    public void postClock(Clock clock) {
        clockMapper.postClock(clock);
    }

    @Override
    public int putClock(Clock clock) {
        return clockMapper.putClock(clock);
    }

    //获取当前日期的状态
    @Override
    public Integer getClockState(Integer userId, Date clockDatetime) {
        return clockMapper.getClockState(userId , clockDatetime);
    }

    @Override
    public Date getClockDatetime(Integer userId) {
        return clockMapper.getClockDatetime(userId);
    }

    @Override
    public Time getTimeDiff(Date d1, Date d2) {
        return clockMapper.getTimeDiff(d1,d2);
    }

    @Override
    public Integer selectDailyList(@Param("clockDatetime1") String dateString,@Param("userId") Integer userId) {
        return clockMapper.selectDailyList(dateString,userId);
    }

    @Override
    public void insertIntoDailyList(DailyList dailyList) {
        clockMapper.insertIntoDailyList(dailyList);
    }

    @Override
    public void insertIntoDailyListById(@Param("dailyListId") Integer dailyListId, @Param("timeDiff") Time timeDiff) {
        clockMapper.insertIntoDailyListById(dailyListId,timeDiff);
    }

    @Override
    public Integer selectGeneralList(Integer userId) {
        return clockMapper.selectGeneralList(userId);
    }

    @Override
    public void insertIntoGeneralList(GeneralList generalList) {
        clockMapper.insertIntoGeneralList(generalList);
    }

    @Override
    public void updateGeneralList(Integer generalListId, Time timeDiff) {
        clockMapper.updateGeneralList(generalListId,timeDiff);
    }

    @Override
    public Integer selectWeeklyList(Integer userId) {
        return clockMapper.selectWeeklyList(userId);
    }

    @Override
    public void insertIntoWeeklyListById(WeeklyList weeklyList) {
        clockMapper.insertIntoWeeklyListById(weeklyList);
    }

    @Override
    public void updateWeeklyList(Integer weeklyListId, Time timeDiff) {
        clockMapper.updateWeeklyList(weeklyListId,timeDiff);
    }

    @Override
    public List<DailyList> selectDailyList(DailyList dailyList) {
        List<DailyList> dailyLists = clockMapper.selectDailyListList(dailyList);
        for(DailyList dailyList1 : dailyLists){
            SysUser sysUser = sysUserMapper.selectUserById((long) dailyList1.getUserId());
            dailyList1.setSysUser(sysUser);
        }
        return dailyLists;
    }

    @Override
    public int deleteWebDailyListByDailyListIds(Integer[] dailyListIds) {
        return clockMapper.deleteWebDailyListByDailyListIds(dailyListIds);
    }


    @Override
    public List<WeeklyList> selectWeeklyListList(WeeklyList weeklyList) {
        List<WeeklyList> weeklyLists = clockMapper.selectWeeklyListList(weeklyList);
        for(WeeklyList weeklyList1 : weeklyLists){
            SysUser sysUser = sysUserMapper.selectUserById((long) weeklyList1.getUserId());
            weeklyList1.setSysUser(sysUser);
        }
        return weeklyLists;
    }

    @Override
    public List<GeneralList> selectGeneralListList(GeneralList generalList) {
        List<GeneralList> generalLists = clockMapper.selectGeneralListList(generalList);
        for(GeneralList generalLists1 : generalLists){
            SysUser sysUser = sysUserMapper.selectUserById((long) generalLists1.getUserId());
            generalLists1.setSysUser(sysUser);
        }
        return generalLists;
    }

    @Override
    public int insertWebDailyList(DailyList dailyList) {
        return clockMapper.insertWebDailyList(dailyList);
    }

    @Override
    public DailyList selectWebDailyListByDailyListId(Integer dailyListId) {
        return clockMapper.selectWebDailyListByDailyListId(dailyListId);
    }

    @Override
    public GeneralList selectWebGeneralListByGeneralListId(Integer generalListId) {
        return clockMapper.selectWebGeneralListByGeneralListId(generalListId);
    }

    @Override
    public int insertWebGeneralList(GeneralList generalList) {
        return clockMapper.insertWebGeneralList(generalList);
    }

    @Override
    public int updateWebGeneralList(GeneralList generalList) {
        return clockMapper.updateWebGeneralList(generalList);
    }

    @Override
    public int deleteWebGeneralListByGeneralListIds(Integer[] generalListIds) {
        return clockMapper.deleteWebGeneralListByGeneralListIds(generalListIds);
    }
}
